package in.muton.edushare.pages.univ;

import in.muton.edushare.wicket.models.CayenneList;
import in.muton.edushare.wicket.models.InnerList;
import in.muton.panels.paginator.EntityListing;
import in.muton.panels.paginator.badgehelpers.course.DeptBadgeInterface;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

import com.edushare.common.constants.ApplicationConstants;
import com.edushare.common.vo.Departments;

public class UnivDept extends UnivBase {

	public UnivDept(PageParameters params) {
		super(params);
		DeptBadgeInterface dbi = new DeptBadgeInterface(getModel());

		Form<Void> f = new Form<Void>("filterForm");
		add(f);
		f.add(new TextField<String>("filterString", new PropertyModel<String>(
				this, "filterString")));

		add(new EntityListing<Departments>("thumbList",
				new InnerList<Departments>() {
					private static final long serialVersionUID = -5396409052930253629L;

					@Override
					public List<IModel<Departments>> getObject() {
						return filterByString(ud.getAllDept(), filterString)
								.getObject();
					}
				}, dbi, this));
	}

	public CayenneList<Departments> filterByString(
			CayenneList<Departments> deptList, String str) {
		CayenneList<Departments> filteredList = new CayenneList<Departments>(
				null);
		List<IModel<Departments>> deptTempList = deptList.getObject();
		for (IModel<Departments> d : deptTempList) {
			if (d.getObject().getDeptName().toLowerCase().contains(
					str.toLowerCase().trim()))
				filteredList.add(d.getObject());
		}
		return filteredList;
	}

	@Override
	public String getActivePage(PageParameters p) {
		return "UnivDept";
	}

	@Override
	public String getPageTitle() {
		return getLoggedInUser().getCompleteUserName() + " | "
				+ getModel().getObject().getUniversityName()
				+ " | Departments | " + ApplicationConstants.APPLICATION_NAME;
	}

	public void setFilterString(String filterString) {
		this.filterString = filterString;
	}

	public String getFilterString() {
		return filterString;
	}

	private String filterString = "";

}
